package com.ThreadGroup;

/**
 * @author Zhang Guangyong
 * @desacription 线程组测试
 * @date 2019年08月20日 10:03
 */
class MyThread extends Thread {
    public MyThread(String name) {
        super(name);
    }

    public MyThread(ThreadGroup threadGroup, String name) {
        super(threadGroup, name);
    }

    public void run() {
        for (int i = 0; i < 20; i++) {
            System.out.println(getName() + "线程的i变量" + i);
        }
    }


}

public class ThreadGroupTest {

    public static void main(String[] args) {
        ThreadGroup mainGroup = Thread.currentThread().getThreadGroup();

        System.out.println(mainGroup); //线程组名
        System.out.println(mainGroup.isDaemon()); //是否后台线程组

        new MyThread("主线程组的线程").start();

        ThreadGroup group = new ThreadGroup("新线程组");

        group.setDaemon(true);

        System.out.println(group.isDaemon()); //是否后台线程组

        MyThread myThread = new MyThread(group, "新线程组的线程");
        myThread.start();
        System.out.println(myThread.getThreadGroup()); //线程组名
    }
}
